package com.db.service.bank;

import com.db.domain.bank.*;

public class ClientParser {
    public static Client parseLineToClient(String line) {
        String type = null;
        double balance = 0;
        double overdraft = 0;
        String name = null;
        Gender gender = null;

        for (String part : line.split(";")) {
            String[] params = part.split("=");
            switch(params[0]) {
                case ("accounttype"):
                    type = params[1];
                    break;
                case ("balance"):
                    balance = Double.valueOf(params[1]);
                    break;
                case ("overdraft"):
                    overdraft = Double.valueOf(params[1]);
                    break;
                case ("name"):
                    name = params[1];
                    break;
                case ("gender"):
                    gender = "f".equals(params[1]) ? Gender.FEMALE : Gender.MALE;
                    break;
                default:
                    System.err.println("");
            }
        }
        Account account = null;
        switch(type) {
            case "c" :
                account = new CheckingAccount(balance, overdraft);
                break;
            case "s":
                account = new SavingAccount(balance);
                break;
        }
        return new Client(name, gender, account);
    }
}
